home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / HyperXExamples / CExamples / Reduce.c < prev   
Encoding:
C/C++ Source or Header  |  1998-12-03  |  784 b   |  41 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    Reduce    - XFCN to compress runs of spaces and tabs to a space
  3.  *                    - Fully MPW 3.0 compatible
  4.  *                    - written by Dan Allen
  5.  *
  6.  *    Sample HyperTalk line:
  7.  *
  8.  *    put reduce(field 1) into field 1 -- reduce tabs & spaces
  9.  *
  10.  */
  11.  
  12. #include <Types.h>
  13. #include <Memory.h>
  14. #include <HyperXCmd.h>
  15.  
  16. pascal void MoveHHiTrap(Handle h) = { 0x205F, 0xA064 }; 
  17.  
  18. pascal void EntryPoint(XCmdPtr paramPtr)
  19. {
  20.     char        *p,*q;
  21.     Handle    h;
  22.  
  23.     if(paramPtr->paramCount != 1) return;
  24.     MoveHHiTrap(paramPtr->params[0]);
  25.     h = NewHandle(GetHandleSize(paramPtr->params[0]));
  26.     if (!h) return;
  27.     p = *(paramPtr->params[0]);
  28.     q = *h;
  29.     while(*p) {
  30.         if (*p == '\t' || *p == ' ') {
  31.             do
  32.                 p++;
  33.             while (*p == '\t' || *p == ' ');
  34.             *q++ = ' ';
  35.         } else
  36.             *q++ = *p++;
  37.     }
  38.     *q = '\0';
  39.     paramPtr->returnValue = h;
  40. }
  41.